<template>
  <el-dialog
    title="账单详细列表"
    :close-on-click-modal="false"
    append-to-body
    center
    width="70%"
    :visible.sync="visible">
  <div class="mod-config">
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
<!--      <el-table-column-->
<!--        type="selection"-->
<!--        header-align="center"-->
<!--        align="center"-->
<!--        width="50">-->
<!--      </el-table-column>-->
      <el-table-column
        prop="orderId"
        header-align="center"
        align="center"
        label="订单ID">
      </el-table-column>
      <el-table-column
        prop="money"
        header-align="center"
        align="center"
        label="挂账金额">
        <template slot-scope="scope">
          <div style="color: red">￥{{scope.row.money}}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="type"
        header-align="center"
        align="center"
        label="类型">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.type === 1">堂吃</el-tag>
          <el-tag v-if="scope.row.type === 2">快餐</el-tag>
          <el-tag v-if="scope.row.type === 3">外卖</el-tag>
        </template>
      </el-table-column>
<!--      <el-table-column-->
<!--        prop="status"-->
<!--        header-align="center"-->
<!--        align="center"-->
<!--        label="状态">-->
<!--        <template slot-scope="scope">-->
<!--          <el-tag v-if="scope.row.status === 1">未结</el-tag>-->
<!--          <el-tag v-if="scope.row.status === 2" type="danger">已结</el-tag>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column
        prop="foodVo"
        header-align="center"
        align="center"
        width="300px"
        label="菜品集合">
        <template slot-scope="scope">
          <div v-for="item in JSON.parse(scope.row.foodVo)">
            {{ item.foodName }}/{{ item.foodNum }}份
            <font style="color: red;">￥{{ item.total }}元</font>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="settlementLink"
        header-align="center"
        align="center"
        label="结账人">
      </el-table-column>
      <el-table-column
        prop="settlementTel"
        header-align="center"
        align="center"
        label="结账人电话">
      </el-table-column>
      <el-table-column
        prop="settlementTime"
        header-align="center"
        align="center"
        label="结账时间">
      </el-table-column>

    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>

  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,
        id:'',
        visible:false,
        checkOutForm:{

        },
        checkOutVisible:false,
        disabledSubmit:false,
        allCheckSign:''
      }
    },
    components: {

    },
    activated () {
      this.getDataList(this.row)
    },
    methods: {

      // 获取数据列表
      getDataList (row) {
        this.visible = true
        this.row = row
        this.$http({
          url: this.$http.adornUrl('/store/tstoreaccountdetail/getDetailList'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'accountUnitId':this.row.accountUnitId,
            'settlementLink':this.row.settlementLink,
            'settlementTel':this.row.settlementTel,
            'time':this.row.time,
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          //this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList(this.row)
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList(this.row)
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/store/tstoreaccountlist/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList(this.row)
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
